#include <vector>
#include <string>
#include <unordered_map>
#include <algorithm>
using namespace std;
/*
 * @lc app=leetcode.cn id=49 lang=cpp
 *
 * [49] 字母异位词分组
 */

// @lc code=start
class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        unordered_map<string, int> mapper;
        vector<vector<string>> res;
        int cur = 0;
        for (int i = 0; i < strs.size(); i++) {
            string t = strs[i];
            sort(t.begin(), t.end());
            if (mapper.count(t) < 1) {
                mapper[t] = cur; cur++;
                res.push_back({strs[i]});
            }
            else {
                res[mapper[t]].push_back(strs[i]);
            }
        }
        return res;
    }
};
// @lc code=end

